import { defineStore } from 'pinia'
import { ssMap3DDataTypes } from './ssMapDataStore.d'
import { setLocalStorage, getLocalStorage } from '@/utils' //本地会话 操作

// 定义动态键值类型
interface TilesetConfig {
  [key: string]: unknown;
}

//三维 数据存储 记录
export const ssmap3DDateStore = defineStore({
  id:"ssmap3DDateStore",
  state: (): ssMap3DDataTypes => ({
      modelGraphicsTileset: {},
      modelGraphicsModel:  {},
      imageryproviderArcGis:  {},
      imageryproviderTdt:  {},
      globeDemTerrain: {},
  }),
  getters:{
    getModelGraphicsTilesetValue: (state) => (key: string): unknown | undefined => {
      return state.modelGraphicsTileset[key]
    },
    getModelGraphicsModelValue: (state) => (key: string): unknown | undefined => {
      return state.modelGraphicsModel[key]
    },
    getImageryproviderArcGisValue: (state) => (key: string): unknown | undefined => {
      return state.imageryproviderArcGis[key]
    },
    getImageryproviderTdtlValue: (state) => (key: string): unknown | undefined => {
      return state.imageryproviderTdt[key]
    },
    getGlobeDemTerrainValue: (state) => (key: string): unknown | undefined => {
      return state.globeDemTerrain[key]
    },
  },
  actions:{
   //动态键值更新
    SET_MODELGRAPHICS_TILESET(key: keyof TilesetConfig, value: TilesetConfig[keyof TilesetConfig]) {
      if(!key) {
        console.error(`需要存储的key值：${key},请重新添加`)
        return
      }
        this.modelGraphicsTileset = {
        ...this.modelGraphicsTileset,
        [key]: value
      }
    },SET_MODELGRAPHICS_MODEL(key: keyof TilesetConfig, value: TilesetConfig[keyof TilesetConfig]) {
      if(!key) {
        console.error(`需要存储的key值：${key},请重新添加`)
        return
      }
        this.modelGraphicsModel = {
        ...this.modelGraphicsModel,
        [key]: value
      }
    },SET_IMAGERYPROVIDER_AECGIS(key: keyof TilesetConfig, value: TilesetConfig[keyof TilesetConfig]) {
      if(!key) {
        console.error(`需要存储的key值：${key},请重新添加`)
        return
      }
        this.imageryproviderArcGis = {
        ...this.imageryproviderArcGis,
        [key]: value
      }
    },SET_IMAGERYPROVIDER_TDT(key: keyof TilesetConfig, value: TilesetConfig[keyof TilesetConfig]) {
      if(!key) {
        console.error(`需要存储的key值：${key},请重新添加`)
        return
      }
        this.imageryproviderTdt = {
        ...this.imageryproviderTdt,
        [key]: value
      }
    },SET_GLOBE_DEMTERRAIN(key: keyof TilesetConfig, value: TilesetConfig[keyof TilesetConfig]) {
      if(!key) {
        console.error(`需要存储的key值：${key},请重新添加`)
        return
      }
        this.globeDemTerrain = {
        ...this.globeDemTerrain,
        [key]: value
      }
    },
  }
})